package com.gec.obwiki.controller;


import com.gec.obwiki.domain.dto.CategoryQueryReq;
import com.gec.obwiki.domain.dto.CategorySaveReq;
import com.gec.obwiki.domain.vo.CategoryQueryResp;
import com.gec.obwiki.domain.vo.PageResp;
import com.gec.obwiki.resp.CommonResp;

import com.gec.obwiki.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;


    /**
     * 根据名称查询分页列表
     * @param
     * @return
     */
    @GetMapping("/all")
    public CommonResp all() {
        CommonResp<List<CategoryQueryResp>> resp = new CommonResp<>(true,"查询成功",null);

        List<CategoryQueryResp> list = categoryService.all();
        resp.setContent(list);
        return resp;
    }

    /**
     * 保存分类信息
     * @param req
     * @return
     */
    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody CategorySaveReq req) {
        CommonResp resp = new CommonResp<>(true,"成功",null);
        categoryService.save(req);
        return resp;
    }

    /**
     * 删除分类信息
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable Long id) {
        CommonResp resp = new CommonResp<>(true,"删除成功",null);
        categoryService.delete(id);
        return resp;
    }
}